//
//  ViewController.m
//  Elimination
//
//  Created by A-01 on 2020/7/1.
//  Copyright © 2020 A-01. All rights reserved.
//

#import "ViewController.h"
#import "StartViewController.h"
#import "RecordViewController.h"
#import "IntroductionViewController.h"

@interface ViewController ()

@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UIImageView * rightImageView;
@property (nonatomic, strong)UIButton * startButton;
@property (nonatomic, strong)UIButton * recordButton;
@property (nonatomic, strong)UIButton * introButton;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.backButton.hidden = YES;
    
    [self setupUI];
}


- (void)setupUI{
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.text = @"Color Geometric Elimination";
    titleLabel.textColor = ZRWhiteColor;
    titleLabel.font = [UIFont fontWithName:@"FZSEJW--GB1-0" size:35];
    
    self.titleLabel = titleLabel;
    
    [self.view addSubview:self.titleLabel];
    
    UIImageView * rightImageView = [UIImageView new];
    
    rightImageView.image = [UIImage imageNamed:@"homeImg"];
    
    self.rightImageView = rightImageView;
    
    [self.view addSubview:self.rightImageView];
    
    
    self.startButton = [self setupButtonWithTitle:@"Start"];
    [self.view addSubview:self.startButton];
    self.recordButton = [self setupButtonWithTitle:@"Record"];
    [self.view addSubview:self.recordButton];
    self.introButton = [self setupButtonWithTitle:@"Introduction"];
    [self.view addSubview:self.introButton];
}


- (void)clickButton:(UIButton *)button{
    
    if (button == self.startButton) {
        
        StartViewController * startVC = [StartViewController new];
        
        [self.navigationController pushViewController:startVC animated:YES];
    }else if (button == self.recordButton){
        
        RecordViewController * recordVC = [RecordViewController new];
        
        [self.navigationController pushViewController:recordVC animated:YES];
    }else{
        
        IntroductionViewController * introVC = [IntroductionViewController new];
        
        [self.navigationController pushViewController:introVC animated:YES];
    }
    
}


-(void)viewDidLayoutSubviews{
    
    [super viewDidLayoutSubviews];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(50);
        make.top.mas_equalTo(self.view).offset(60);
    }];
    
    [self.rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.view);
        make.trailing.mas_equalTo(self.view).offset(-60);
        make.height.mas_equalTo(251);
        make.width.mas_equalTo(246);
    }];
    
    [self.startButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(120);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(30);
        make.height.mas_equalTo(48);
        make.width.mas_equalTo(200);
    }];
    
    [self.recordButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.width.height.mas_equalTo(self.startButton);
        make.top.mas_equalTo(self.startButton.mas_bottom).offset(25);
    }];
    
    [self.introButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.width.height.mas_equalTo(self.recordButton);
        make.top.mas_equalTo(self.recordButton.mas_bottom).offset(25);
    }];
}


- (UIButton *)setupButtonWithTitle:(NSString *)title{
    
    UIButton * button = [UIButton new];
    
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:ZRWhiteColor forState:UIControlStateNormal];
    [button setBackgroundColor:[UIColor colorWithHexString:@"4198FF"]];
    [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    button.titleLabel.font = [UIFont fontWithName:@"FZSEJW--GB1-0" size:24];
    button.layer.cornerRadius = 24;
    button.layer.masksToBounds = YES;
    
    return button;
}

@end
